/**
 * Created by meiguizhinian on 2018/7/5
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//cocos2dx class
unblockme.RateDialog = LLDialog.extend({
	ctor: function (form) {
		this._super(form);

		for (let i=0; i!==5; ++i) {
			let name = "bt"+(i+1);
			let button = this._formNode.getChildByName(name, ivy.UICheckBox);
			if (button) {
				button.onCheckChanged().add(this.updateRate.bind(this, i));
			}
		}
	},

	updateRate : function(rate) {
		cc.log("rate:%d",rate);
		for (let i=0; i!==5; ++i) {
			let name = "bt"+(i+1);
			let button = this._formNode.getChildByName(name, ivy.UICheckBox);
			if (i<=rate) {
				button.setCheckedWithoutChangeCallFunc(false);
			} else {
				button.setCheckedWithoutChangeCallFunc(true);
			}
		}
		this.close(1);
		if (rate>=3) {
			//TODO：IvySDK
			//IvySDK::rateUs();
		}
	}
});

unblockme.RateDialog.create = function (form) {
	return new unblockme.RateDialog(form);
};
